package com.dc.refactoring._5_简化函数调用._13_ReplaceErrorCodeWithException.oldObject;

/**
 * Description: 账户信息
 * 消费案例，消费钱判断，账户金额是否足够，如果够，扣钱，返回正常状态码，否则返回错误码
 * @author: gdc
 * @date: 2020/12/12
 * @version 1.0
 */
public class Account {

    /**
     * 账户结余
     */
    private double balance;

    /**
     * 余额不足，返回状态码 -1，结算成功，返回0
     * @param amount        结算金额
     * @return              结算状态码
     */
    int withDraw(double amount) {
        if (amount > balance) {
            return -1;
        } else {
            balance -= amount;
            return 0;
        }
    }




 }


